********regressions*******
capture program drop plotreg
program plotreg
	
	local dv "`1'"
	local scale1 `2'
	local scale2 `3'
	local log `4'
	local imp `5'
	local num "`6'"
	local nocont `7'

	qui{
	forval q = 1/4{

		//controls
		local controls `"sex asian black hispan i.year i.head_coll i.age_group#i.div head_mar head_constr_manu house_value parent_inc own_house"'
		
		if `nocont' == 1{
			local controls `"i.age_group#i.div i.year"'
		}
		
		//run regression
		areg `dv' age_dum* `controls' [aw = weight] if parent_inc_quart == `q', absorb(cz_2000) vce(cluster cz_2000)

		//storing estimates
		forval i = 1/4{
			local effect_`i'_`q' = round(_b[age_dum_`i'], 0.001)
			local se_`i'_`q' = round(_se[age_dum_`i'], 0.001)
			su `dv' [aw = weight] if age_group == `i' & parent_inc_quart == `q'
			local mean_`i'_`q' = round(`r(mean)', 0.001)
		}
	}

	//create data to make graph out of
	preserve
	clear
	set obs 16
	gen group = .
	gen effect = .
	gen se = .
	gen mean = .
	gen quart = .
	forval q = 1/4{
		forval i = 1/4{
			local line = (`q'-1)*4 + `i'
			replace quart = `q' in `line'
			replace group = `i' in `line'
			replace effect = `effect_`i'_`q'' in `line'
			replace se = `se_`i'_`q'' in `line'
			replace mean = `mean_`i'_`q'' in `line'
		}
	}
	}

	//upper, lower bounds
	gen ub = effect + 1.96*se
	gen lb = effect - 1.96*se
	local step1 = `scale1'/2
	local step2 = `scale2'/2

	//fancy graphs over quartiles
	forval q = 1/4{
		if `log' == 1{
			twoway connected effect group if quart == `q', graphregion(color(white)) bgcolor(white) ylabel(-`scale1'(`step1')`scale1', angle(0) grid) ///
			xlabel(1 "17-19" 2 "20-22" 3 "23-25" 4 "26-28") xtitle("Age Group") ytitle("Effect") lc(black) mc(black) ///
			|| line ub group if quart == `q', lp(dash) lc(black) || line lb group if quart == `q', lp(dash) lc(black) ///
			legend(order(1 "Effect")) yline(0) title("Parent Quartile `q'") saving(graph`q', replace)
		}
		else if `log'!=1{
			twoway connected effect group if quart == `q', graphregion(color(white)) bgcolor(white) ylabel(-`scale1'(`step1')`scale1', angle(0) grid) ///
			xlabel(1 "17-19" 2 "20-22" 3 "23-25" 4 "26-28") xtitle("Age Group") ytitle("Effect") lc(black) mc(black) ///
			|| line ub group if quart == `q', lp(dash) lc(black) || line lb group if quart == `q', lp(dash) lc(black) ///
			|| connected mean group if quart == `q', yaxis(2) ytitle("Basis", axis(2)) ylabel(-`scale2'(`step2')`scale2', axis(2) angle(0) grid) ms(T) mc(black) lc(black) ///
			legend(order(1 "Effect" 4 "Basis")) yline(0) title("Parent Quartile `q'") saving(graph`q', replace)
		}
	}
	graph combine graph1.gph graph2.gph graph3.gph graph4.gph, graphregion(color(white))
	if `imp'==0{
		graph export "$disc/effects_quart_`dv'_T13.png", replace width(1000)
	}
	else if `imp'==1{
		graph export "$disc/`num'a_effects_quart_`dv'_T13.png", replace width(1000)
	}
	
	//now report percentage effects over quartiles at final age group
	keep if group == 4	
	gen effect_pct = (effect/mean)*100
	gen se_pct = (se/mean)*100
	
	if `log'==1{
		replace effect_pct = effect
		replace se_pct = se
	}

	serrbar effect_pct se_pct quart, scale(1.96) bgcolor(white) graphregion(color(white)) ///
	ytitle("Percentage Effect, Age 26-28") xlabel(1 "1" 2 "2" 3 "3" 4 "4") xtitle("Parent Income Quartile") yline(0)
	
	if `imp'==0{
		graph export "$disc/effects_pct_quart_`dv'_T13.png", replace width(1000)
	}
	else if `imp'==1{
		graph export "$disc/`num'b_effects_pct_quart_`dv'_T13.png", replace width(1000)	
	}
	//graph close
	restore
end


